package club.hicode.daydayup.sslFile.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.Date;

public class MyClientHandler extends ChannelInboundHandlerAdapter {

	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		System.out.println("client channel open：" + ctx.channel().localAddress() + "channelActive" + '-' + new Date());
		long start = System.currentTimeMillis();

		//String fileUrl = "C:/work/setup/win32_11gR2_client.zip";
		//String fileUrl = "C:/work/setup/ubuntu-14.04.4-desktop-amd64.iso";
		//String fileUrl = "C:/work/setup/jdk-7windows-x64.zip";
		String fileUrl = "/Volumes/Repository/study/小马哥-思否/Spring Cloud/Java 微服务实践 - Spring Cloud 系列（十五）分布式应用跟踪.mp4";
		FileControl fileControl = new FileControl(ctx);
		// send file
		fileControl.sendFile(fileUrl);
		long end = System.currentTimeMillis();
		//System.out.println("cost:" + (end - start));
	}

	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
		System.out.println("channel closed：" + ctx.channel().localAddress() + "channelInactive" + '-' + System
				.currentTimeMillis());
	}


	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
		ctx.flush();
	}

	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		ctx.close();
		//System.out.println("异常退出:" + cause.getMessage());
		cause.printStackTrace();
	}

}
